"""
User proxy agent implementation
"""
from typing import Optional, Dict
from .base import BaseAgent
from ..core.message import Message, MessageType

class UserProxy(BaseAgent):
    """用户代理类，处理用户输入输出"""
    
    def __init__(self, agent_id: str = "user"):
        super().__init__(agent_id)
        
    def forward(self, message: Message) -> Message:
        """
        处理接收到的消息
        如果是接收到的消息，直接打印给用户
        如果是发送消息，将用户输入包装成消息发送出去
        """
        if message.receiver == self.agent_id:
            # 接收到的消息，打印给用户
            if message.type == MessageType.TEXT:
                print(f"\n{message.sender}: {message.content}")
                print('----------------------------------------')

            # 获取用户输入并发送
            user_input = input(f"\n{self.agent_id}: ")
            return self.create_message(
                content=user_input,
                msg_type=MessageType.TEXT,
                receiver=message.sender
            )
            
    def send_message(self, content: str, receiver: Optional[str] = None, 
                    metadata: Optional[Dict] = None) -> Message:
        """
        发送消息的便捷方法
        Args:
            content: 消息内容
            receiver: 接收者ID
            metadata: 元数据
        Returns:
            创建的消息对象
        """
        return self.create_message(
            content=content,
            msg_type=MessageType.TEXT,
            receiver=receiver,
            metadata=metadata
        )
